package com.utils.basehelper.array;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ArrayToList {
	public void arrayToList(String[] arrays) {
		String[] str=new String[] {"hello","world"};

		//1for循环
		List<String> list=new ArrayList<String>();
		for (String string : str) {
			list.add(string);
		}
		
		//2使用asList()
		ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(arrays));

        //3使用Lists.newArrayList
        List<Object> list2 = Lists.newArrayList(arrays);
		
		//3使用Collections.addAll()
		List<String> list3 = new ArrayList<String>(arrays.length);
		Collections.addAll(list3, arrays);
		
		//4 使用Stream中的Collector收集器
		//转换后的List 属于 java.util.ArrayList 能进行正常的增删查操作
		List<String> list5 = Stream.of(str).collect(Collectors.toList());
        List<Integer> intList= Arrays.stream(new int[] { 1, 2, 3, }).boxed().collect(Collectors.toList());
        List<Long> longList= Arrays.stream(new long[] { 1, 2, 3 }).boxed().collect(Collectors.toList());
        List<Double> doubleList= Arrays.stream(new double[] { 1, 2, 3 }).boxed().collect(Collectors.toList());

		
		//5 此方法为 Java9新增方法 使用List.of()
//		List<String> resultList = List.of(str);

	}
}
